﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using ServisniList.Core;

namespace ServisniList.Rukovatelji
{
    public class TrenutniList
    {
        #region Fields

        private static TrenutniList instance = null;

        #endregion

        #region Properties

        public Core.List ListUObradi { get; set; }

        #endregion

        #region Constructor

        private TrenutniList()
        {
            ListUObradi = null;
        }

        #endregion

        #region Msthods

        public static TrenutniList GetInstance()
        {
            if (instance == null)
            {
                instance = new TrenutniList();
            }
            return instance;
        }

        public string GenerirajNoviBrojListica()
        {
            StringBuilder broj = new StringBuilder("");
            Core.Djelatnik djelatnik = Korisnici.GetInstance().TreutnoUlogiraniDjelatnik;
            using (DataModelDataContext context = new DataModelDataContext(ConfigurationManager.ConnectionStrings["ServisniListConnectionString"].ConnectionString))
            {
                int nextId = context.Lists.Count(clan => clan.ZaprimateljID == djelatnik.ID) + 1;
                broj.Append(djelatnik.Simbol);
                broj.Append(DateTime.Now.Year);
                broj.Append(DateTime.Now.Month);
                broj.Append(DateTime.Now.Day);
                broj.Append(nextId);
            }
            return broj.ToString();
        }

        #endregion

    }
}
